package com.zyj.myapplication.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import java.util.List;


import com.zyj.myapplication.R;
import com.zyj.myapplication.Activity.CoachListActivity;
import com.zyj.myapplication.Javabean.Coach;


import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by Administrator on 2017/10/19.
 */

public class CoachListAdapter  extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;//数据存储
    private LayoutInflater mLayoutInflater;//布局

    public CoachListAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_coachlist,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Coach entity = (Coach) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.coach_name.setText(entity.getRealname());
        String address="http://172.24.10.175/workout/Uploads/"+entity.getThumb();
        if(!entity.getThumb().equals("")){
            Picasso.with(mContext).load(address).into(viewHolder.coach_thumb);
        }
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,CoachListActivity.class);
                intent.putExtra("coach_id",entity.getId());

                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return  mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView coach_thumb;
        TextView coach_id,coach_name;
        LinearLayout coach_container;

        public ViewHolder(View itemView) {
            super(itemView);
            coach_container = (LinearLayout) itemView.findViewById(R.id.coach_container);
            coach_name = (TextView) itemView.findViewById(R.id.coach_name);
            coach_thumb = (ImageView) itemView.findViewById(R.id.coach_thumb);

        }
    }
}
